<template>
  <van-row class="main-menu">
    <van-nav-bar left-text="返回" :title="assessType === $vo.AssessType.CORP + '' ? '公司评分统计' : '单位评分统计'" @click-left="doBack"/>
    <div class="waiquanbox">
        <div class="neiquanbox">
          <div class="demo-input-suffix">
            <!-- <div class="inputbox" v-if="topquanxian">
              公司审核部门：
              <el-select clearable @change="chickbumen" v-model="choseque">
                <el-option
                  v-for="(item, i) in options.gskhbm"
                  :key="i"
                  :label="item"
                  :value="item"
                >
                </el-option>
              </el-select>
            </div> -->
            <div class="inputbox">
              单位名称：
              <el-select
                v-model="dwmc"
                placeholder="请选择"
                filterable
                allow-create
                :disabled="datadisabled"
              >
                <el-option
                  v-for="(item, i) in options.dwmc"
                  :key="i"
                  :value="item"
                  :label="item"
                ></el-option>
              </el-select>
            </div>

            <div class="inputbox">
              选择年份：
              <el-date-picker
                v-model="chosedata"
                type="year"
                placeholder="选择年"
                format="yyyy 年"
                value-format="yyyy"
              >
              </el-date-picker>
            </div>
            <div class="inputbox right">
              <el-button
                type="primary"
                @click="getwtDatalist"
                icon="el-icon-search"
                >查询</el-button
              >
            </div>
            <div class="inputbox right">
              <el-button @click="exportExcel">导出表格</el-button>
            </div>
          </div>
          <!-- 公共表格 -->
          <score-ping-list :assessType="assessType" :year="chosedata" :scorpdata="scorpdata"/>
        </div>

      <!-- <el-dialog
        title="加分清单"
        :visible.sync="adddialogVisible"
        width="70%"
      >
        <div class="tablecontent xiaochu">
          <el-table
            :data="addData"
            empty-text="暂无数据"
            stripe
            style="width: 100%"
          >
            <el-table-column prop="wtms" label="问题描述" width="600">
            </el-table-column>
            <el-table-column prop="times" label="时间">
            </el-table-column>
            <el-table-column prop="score" label="加分">
            </el-table-column>
          </el-table>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="adddialogVisible = false"
            >关 闭</el-button
          >
        </span>
      </el-dialog>

      <el-dialog
        title="减分清单"
        :visible.sync="subdialogVisible"
        width="70%"
      >
        <div class="tablecontent xiaochu">
          <el-table
            :data="subData"
            empty-text="暂无数据"
            stripe
            style="width: 100%;margin-top:30px;"
          >
            <el-table-column prop="wtms" label="问题描述" width="600">
            </el-table-column>
            <el-table-column prop="times" label="时间">
            </el-table-column>
            <el-table-column prop="score" label="减分">
            </el-table-column>
          </el-table>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="subdialogVisible = false"
            >关 闭</el-button
          >
        </span>
      </el-dialog> -->

    </div>
  </van-row>
</template>



<script>
import ScorePingList from '@/views/dealtwith/ScorePingList'
/* 下拉框的 默认值 */
import { gskhbm } from "../../utils/excel/option";
/* 导出 */
import {export_json_to_excel} from '../../../public/excel/Export2Excel';

/* 交互api */
import { selectScoreList } from "../../api/dealtwith";
import { Loading } from "element-ui";
export default {
  components: { ScorePingList },
  props:['assessType'],
  data() {
    return {
      department_name: "",
      // addData: [], //弹框加分清单
      // subData: [], //弹框减分清单
      adddialogVisible: false, //公司对应单位
      subdialogVisible: false, //单位对应部门
      datadisabled:false,
      // topquanxian:false,
      active: 0,
      components: {},
      options: {
        //下拉框 选项
        dwmc: ["广州局","贵阳局","昆明局","南宁局","柳州局","天生桥局","梧州局","百色局","曲靖局","大理局","南宁监控中心","检修试验中心"], //单位名称
        gskhbm: [], // 公司考核部门
      },
      loading: false, //加载
      drawer: false,
      activeName: "quanbu",
      dwmc: "",
      // choseque: "",
      departname: "",
      chosedata: '2021',
      tableData:[],
      currentPage: 1, //初始页
      pagesize: 10, // 每页的数据
      wentiData: [
        // {
        //   date: "2016-05-02",
        //   name: "王小虎",
        //   address: "上海市普陀区金沙江路 1518 弄",
        // },
      ],
      scorpdata:[],
    };
  },
  created() {
    //获取当前人用户部门
    if (!this.$store.state.authInfo.user.rectify[0].department_path) {
      this.department_name =
        this.$store.state.authInfo.user.roles.corp.assess_dept[0].department_name; //测试环境
      console.log(this.department_name);
    } else {
      this.department_name = this.$store.state.authInfo.user.rectify[0].department_path; //企业微信
      console.log(this.department_name);
      
    }
    this.options.gskhbm = gskhbm;
  },
  mounted(){
    //var department_name = this.department_name.split('/')
    // if(this.department_name == '超高压输电公司' || department_name[1] == '公司本部'){
    //   this.topquanxian = true
    //   this.dwmc = ''
    //   this.datadisabled = false;
    //   if( department_name[2] == undefined){
    //     this.choseque = '公司本部'
    //     this.departname = ''
    //   }else{
    //   this.choseque = '公司本部->' + department_name[2]
    //   this.departname = department_name[2]
    //   }
      
    //   this.getwtDatalist()
    // }else{
    //   this.topquanxian = false
    //   this.dwmc = department_name[1]
    //   this.datadisabled = true;
    //   this.getwtDatalist()
    // }
    var department_name = this.department_name.split('/')
    if(this.department_name == '超高压输电公司' || department_name[1] == '公司本部'){
      if(this.assessType === this.$vo.AssessType.CORP + ''){
        this.dwmc = ''
      }else{
        this.dwmc = '广州局'
      }
    }else{
      this.dwmc =department_name[1]
      this.datadisabled = true

    }   
    

    this.getwtDatalist()
  },

  methods: {
    //导出
    exportExcel() {
      require.ensure([], () => {
        const tHeader = ['部门名称','总分', '上半年总分', '上半年加分', '上半年减分', '下半年总分', '下半年加分', '下半年减分'] // 对应表格输出的中文title
        const filterVal = ['deptName' ,'total', 'upTotal', 'upAdd', 'upSub', 'downTotal', 'downAdd', 'downSub'] // 对应表格输出的数据
        const list = this.wentiData // 表格data
        const data = this.formatJson(filterVal, list)
        console.log(data)
        export_json_to_excel(tHeader, data, '评分统计') // 对应下载文件的名字
          })
      },
      formatJson(filterVal, jsonData) {
          return jsonData.map(v => filterVal.map(j => v[j]))
      },
    //获取部门
    // chickbumen(){
    //   var choseque = this.choseque.split('->')
    //   console.log(choseque[1])
    //   this.departname = choseque[1]
    // },
    //查询
    getwtDatalist() {
      let loadingInstance = Loading.service({ fullscreen: true });
      var obj = {};
      var department_name = this.department_name.split('/')   
      if(this.department_name == '超高压输电公司' || department_name[1] == '公司本部'){
        obj.type = 0;
      }else{
        obj.type = 1;
      }

      obj.dwmc = this.dwmc; 
      obj.year = this.chosedata;
      obj.type = this.assessType === this.$vo.AssessType.CORP + '' ? 0 : 1;
      // obj.departname = this.departname;
      console.log(obj);
      selectScoreList(obj)
        .then((res) => {
          loadingInstance.close();
          console.log(res);
          this.tableData = res.data.retData
          this.scorpdata = res.data.retData
          if (res.data.retData.length == 0) {
            this.$message({
              type: "warning",
              message: "暂无次查询数据！",
            });
          }

          this.wentiData = res.data.retData;
          this.handleCurrentChangeWenti(1); //重置返回第一页
          //   this.loading = false;
          //   if (res.data.retData != null) {
          //     this.multipleSelections = res.data.retData;
          //   } else {
          //     this.$message({
          //       type: "warning",
          //       message: "当前没有录入数据,临时数据请点击打开查看",
          //     });
          //   }
        })
        .catch((err) => {});
    },

    // //加分清单弹框
    // showadddialogVisible(data) {
    //   this.adddialogVisible = true;
    //   this.addData = data;
    //   console.log(this.addData);
    // },
    // //减分清单弹框
    // showsubdialogVisible(data) {
    //   this.subdialogVisible = true;
    //   this.subData = data;
    //   console.log(this.subData);
    // },

    doBack() {
      this.$router.back();
    },
  },
};
</script>

<style scoped lang="less">
body {
  background: #ccc;
  box-sizing: border-box;
}
.right {
  float: right;
}
.iconblue {
  color: #e2bd06;
}
.taptitle {
  font-size: 18px;
  padding: 10px 0;
  font-weight: bold;
}

.el-tabs__header {
  padding: 30px;
}
.iconsearch {
  color: #409eff !important;
}
.searinput {
  width: 250px;
}
.daoru {
  margin-left: 10px;
}
.pagefanye {
  margin-top: 10px;
}
.searinputshu {
  width: 150px;
}
.inputbox {
  margin-right: 20px;
  display: inline-block;
  margin-top: 20px;
}
.drawerHeight {
  /deep/.el-drawer__container > .el-drawer {
    overflow-y: auto !important;
  }
}
.tablecontent {
  /deep/.cell {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
}
.tablecontent.xiaochu {
  /deep/.cell {
    overflow: unset;
    text-overflow: unset;
    display: unset;
    -webkit-line-clamp: unset;
    -webkit-box-orient: unset;
  }
}

.el-drawer.ltr {
  overflow-y: auto !important;
}
.stepComponent {
  width: 100%-20px;
  padding: 10px 10px 10px 10px;
  margin: 10px 10px 10px 10px;
}
.stepsTitle {
  margin: 10px 0px 10px 10px;
}
.approvalProcess {
  color: #9eadc4;
  font-size: 14px;
  /* width: 100%; */
  margin-left: 20px;
  margin-right: 0px;
  margin-top: 10px;
}
.processing_content {
  //background-color: #d9e5f9;
  box-sizing: border-box;
  padding: 4px;
}
.processing_content_detail {
  width: 137px;
  display: inline-block;
  box-sizing: border-box;
  padding-left: 5px;
}
.step-row {
  min-width: 500px;
  margin-bottom: 12px;
  margin-top: 12px;
}
//    /deep/.el-pagination {
//         white-space: normal;
//     }
// /deep/.van-popup--right{
//   z-index: 3000!important;
// }
</style>
